package org.firebug.metadata.micro.repository.dao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.firebug.metadata.micro.repository.po.RegionPO;

import java.util.List;

/**
 * 地区:t_region
 */
@Mapper
public interface RegionDAO {
    @Update("<script>" +
            "update t_region set deleted=1 where code in " +
            "<foreach collection='code' item='item' index='index' open='(' separator=',' close=')'>" +
            "${item}" +
            "</foreach>" +
            "</script>")
    int deleteByCode(@Param("code") String... code);

    @Select("select * from t_region where code=#{code}")
    RegionPO selectByCode(@Param("code") String code);

    @Select("select * from t_region where pcode=#{pcode} and deleted=0")
    List<RegionPO> selectByPcode(@Param("pcode") String pcode);

    @Select("select * from t_region where pcode=#{pcode} and deleted=0 and sectors & 1<<${sector}")
    List<RegionPO> selectByPcodeSector(@Param("pcode") String pcode, @Param("sector") int sector);
}